﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                float sum = 0;
                while (true)
                {

                    Console.WriteLine("请选择1、存款，2、取款，3、退出");
                    float key = float.Parse(Console.ReadLine());
                    float a = 0;
                    float b = 0;
                    
                    switch (key)
                    {
                        case 1:
                            Console.WriteLine("请输入你要存款的金额");
                            a = float.Parse(Console.ReadLine());
                            sum = sum + a;
                            Console.WriteLine("存款后余额为{0}", sum);
                            break;
                        case 2:
                            Console.WriteLine("请输入你要取款的金额");
                            b = float.Parse(Console.ReadLine());
                            if (b > sum)
                            {
                                throw new ArgumentOutOfRangeException("取款金额大于余额，请重新输入");
                            }
                            else 
                            {
                                sum = sum  - b;
                                Console.WriteLine("取款后余额为{0}", sum);
                            }
                            break;
                        case 3:
                            System.Environment.Exit(0);
                            break;
                        default:
                            break;
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                
                Console.WriteLine("穷光蛋一个，饭都吃不上了");
                hello();
            }
            Console.ReadKey(true);
        }
        public static void hello()
        {
            try
            {
                float sum = 0;
                while (true)
                {

                    Console.WriteLine("请选择1、存款，2、取款，3、退出");
                    float key = float.Parse(Console.ReadLine());
                    float a = 0;
                    float b = 0;
                    
                    switch (key)
                    {
                        case 1:
                            Console.WriteLine("请输入你要存款的金额");
                            a = float.Parse(Console.ReadLine());
                            sum = sum + a;
                            Console.WriteLine("存款后余额为{0}", sum);
                            break;
                        case 2:
                            Console.WriteLine("请输入你要取款的金额");
                            b = float.Parse(Console.ReadLine());
                            if (b > sum)
                            {
                                throw new ArgumentOutOfRangeException("取款金额大于余额，请重新输入");
                            }
                            else
                            {
                                sum = sum - b;
                                Console.WriteLine("取款后余额为{0}", sum);
                            }
                            break;
                        case 3:
                            System.Environment.Exit(0);
                            break;
                        default:
                            break;
                    }
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {

                Console.WriteLine("穷光蛋一个，饭都吃不上了");
                hello();
            }
        }
    }
}
